package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueReportVo;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;

    @Override
    @Transactional // 事务
    public void addClueTrackRecord(ClueTrackRecordVo vo) {

        // 添加TbClueTrackRecord 线索跟进表
        TbClueTrackRecord Record = new TbClueTrackRecord();
        BeanUtils.copyProperties(vo,Record); //复制数据到record
        //  由于查询需要用到用户名 调用工具类获取用户名
        String username = SecurityUtils.getUsername();
        Record.setCreateBy(username);  // 跟进人
        Record.setCreateTime(new Date()); // 时间
        tbClueTrackRecordMapper.addClueTrackRecord(Record);

        // 修改clue线索表
        TbClue clue = new TbClue();
        BeanUtils.copyProperties(vo,clue);
        clue.setId(vo.getClueId()); // 注入ID
        clue.setStatus(TbClue.StatusType.FOLLOWING.getValue());  //修改状态为跟进中2
        tbClueMapper.updateTbClue(clue);

    }

    @Override
    public List<TbClueTrackRecord> seleteList(Long clueId) {
       // List<TableDataInfo> tableDataInfos = tbClueTrackRecordMapper.seleteList(clueId);
        return tbClueTrackRecordMapper.seleteList(clueId);
    }
}
